package algorithm;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class Utilities {
    public static int isNumber(String valueString) {
	Pattern pattern = Pattern.compile("[0-9]*");
	if (pattern.matcher(valueString).matches()) {
	    return Integer.parseInt(valueString);
	} else {
	    return -1;
	}
    }
    public static int[] integerToInt(ArrayList<Integer> numberList){
	int[] numbers = new int[numberList.size()];
	int i = 0;
	for(Integer num: numberList){
	    numbers[i++] = num;
	}
	return numbers;
    }
    public static Point[] getArraws(int x1,int y1, int x2, int y2){
	Point[] points = new Point[4];
	if(x2 < x1 && y1 == y2){
	    x1-=6;
	    x2+=6;
	    points[0] = new Point(x1, y1);
	    points[1] = new Point(x2, y2);
	    points[2] = new Point(x2+5, y2+3);
	    points[3] = new Point(x2+5, y2-3);
	}else if(x2 == x1 && y2 < y1){
	    y1-=6;
	    y2+=6;
	    points[0] = new Point(x1, y1);
	    points[1] = new Point(x2, y2);
	    points[2] = new Point(x2+3, y2+5);
	    points[3] = new Point(x2-3, y2+5);
	}else if(x2<x1 && y2<y1){
	    x1-=6;
	    y1-=4;
	    x2+=4;
	    y2+=6;
	    points[0] = new Point(x1, y1);
	    points[1] = new Point(x2, y2);
	    points[2] = new Point(x2+5, y2+1);
	    points[3] = new Point(x2+1, y2+5);
	}
//	else if(x2 > x1 && y1 == y2){
//	    points[0] = new Point(x2-5, y2+5);
//	    points[1] = new Point(x2-5, y2-5);
//	}else if(x2 == x1 && y2 < y1){
//	    points[0] = new Point(x2+5, y2-5);
//	    points[1] = new Point(x2-5, y2-5);
//	}else if(x2>x1 && y2>y1){
//	    points[0] = new Point(x2-5, y2-2);
//	    points[1] = new Point(x2-2, y2-5);
//	}else if(x2 > x1 && y2 < y1){
//	    points[0] = new Point(x2-5, y2+2);
//	    points[1] = new Point(x2-2, y2+5);
//	}else if(x2<x1 && y2>y1){
//	    points[0] = new Point(x2-2, y2-5);
//	    points[1] = new Point(x2-5, y2-2);
//	}
	return points;
    }
    
    public static ArrayList<ArrayList<Integer>> makeGoods(){
	ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
	ArrayList<Integer> weightsArrayList = new ArrayList<Integer>();
	ArrayList<Integer> valueArrayList = new ArrayList<Integer>();
	int counts = 4 + (int)(Math.random()*4);
	for(int i=0; i<counts; i++){
	    int weight = 2 + (int)(Math.random()*6);
	    int value = 10 + (int)(Math.random()*30);
	    weightsArrayList.add(weight);
	    valueArrayList.add(value);
	}
	list.add(weightsArrayList);
	list.add(valueArrayList);
	return list;
    }
    
    public static ArrayList<String> makeCharacters(){
	ArrayList<String> stringList = new ArrayList<String>();
	int counts = 10 + (int)(Math.random()*8);
	StringBuilder builder1 = new StringBuilder();
	StringBuilder builder2 = new StringBuilder();
	char[] characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
	int characterLength = characters.length;
	for(int i=0; i<counts; i++){
	    int index = (int)(Math.random()*characterLength);
	    builder1.append(characters[index]);
	    int index2 = (int)(Math.random()*characterLength);
	    builder2.append(characters[index2]);
	}
	stringList.add(builder1.toString());
	stringList.add(builder2.toString());
	return stringList;
    }
    
    public static ArrayList<Point> makeMartrix(){
	ArrayList<Point> list = new ArrayList<Point>();
	int counts = 4 + (int)(Math.random()*4);
	for(int i=0; i<counts; i++){
	    int num1 = 5 + (int)(Math.random()*25);
	    int num2 = 5 + (int)(Math.random()*25);
	    Point point = new Point(num1, num2);
	    list.add(point);
	}
	return list;
    }
    
    public static String makeNumbersequence(){
	StringBuilder builder = new StringBuilder();
	int counts = 8 + (int) (Math.random() * 7);
	for (int i = 0; i < counts; i++) {
	    int num = (int) (Math.random() * 100);
	    double fu = Math.random();
	    if (fu > 0.5) {
		num = -num;
	    }
	    builder.append(num).append(",");
	}
	builder.replace(builder.length() - 1, builder.length(), "");
	return builder.toString();
    }
}
